package com.atyun.gaojin.notify.mailQQNotify;

import com.atyun.gaojin.notify.AlterNotify;
import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 邮件方式发送任务拒绝告警
 * @Author: 云水瑶
 * @Date: 2025/5/1
*/
@Slf4j
public class MailQQNotify implements AlterNotify {

    @Override
    public void sendAlterNotify(String poolName, Runnable command, ThreadPoolExecutor executor) {
        log.error("准备发送QQ邮箱告警");
        HashSet<String> set = new HashSet<>();
        set.add("2903678386@qq.com");
        set.add("2579895177@qq.com");
//        set.add("3174956220@qq.com");
//        set.add("2338576883@qq.com");
        String content = "线程池告警！！！线程池" + poolName +
                "任务处理被拒绝\n活跃线程：" + executor.getActiveCount() + "/" + executor.getMaximumPoolSize() +
                "\n队列：" + executor.getQueue().size() + "/" + (executor.getQueue().size() + executor.getQueue().remainingCapacity()) +
                "\n任务类型：" + command.getClass().getSimpleName();
        MailQQUtil.sendEmail(set, "线程池" + poolName + "服务告警通知", content);
    }

    @Override
    public String shouldAlterNotify(String poolName, Runnable command, ThreadPoolExecutor executor) {
        String content = "线程池告警！！！线程池" + poolName +
                "任务处理被拒绝\n活跃线程：" + executor.getActiveCount() + "/" + executor.getMaximumPoolSize() +
                "\n队列：" + executor.getQueue().size() + "/" + (executor.getQueue().size() + executor.getQueue().remainingCapacity()) +
                "\n任务类型：" + command.getClass().getSimpleName();
        return content;
    }
}
